#include "MarsPrecompile.h"

#include "MarsType.h"
#include "MarsVertexShader.h"
#include "MarsInputLayout.h"
#include "MarsRenderer.h"

using namespace Graphics;
using namespace Core;

bool InputLayout::Bind( VertexShader& vertexShader )
{
	HRESULT d3dResult = Renderer::Instance().GetDevice()->CreateInputLayout( 
		&m_vElements[ 0 ], 
		m_vElements.size(),
		vertexShader.GetBuffer()->GetBufferPointer( ), 
		vertexShader.GetBuffer()->GetBufferSize( ),
		&m_pInputLayout );

	if ( FAILED( d3dResult ) )
	{
		return false;
	}

	m_pVertexShader = &vertexShader;

	return true;
}

void InputLayout::AddElement( const char*					pSemanticName, 
							  uint32						iSemanticIndex, 
							  DXGI_FORMAT					format, 
							  uint32						iSlot, 
							  uint32						iOffset, 
							  D3D11_INPUT_CLASSIFICATION	iClassification, 
							  uint32						iInstanceDataStepRate )
{
	D3D11_INPUT_ELEMENT_DESC desc = { pSemanticName, iSemanticIndex, format, iSlot, iOffset, iClassification, iInstanceDataStepRate };
	m_vElements.push_back( desc );
}
